package netapp.tcp_4;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class Server {
    private static final ExecutorService POOL = new ThreadPoolExecutor(
            5, 10, 60, TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(5), Executors.defaultThreadFactory(),
            new ThreadPoolExecutor.CallerRunsPolicy()
    );
    public static void main(String[] args) throws IOException {
        // 创建服务器对象
        ServerSocket ss = new ServerSocket(12306);
        // 优化1：将当前服务端放到循环中

        while (true) {
            Socket accept = ss.accept();
            POOL.submit(new ThreadSocket(accept));
        }
        // 关闭服务端
//        ss.close();
    }
}
